import Calculator.MyDC;
import Calculator.ShuntingYard;
import ProduceFormula.formula;

import java.util.InputMismatchException;
import java.util.Scanner;

public class Arithmatic {
    public static void main(String[] args) {
        int i = 0, count = 0;
        System.out.print("请输入要生成的题目数：");
        Scanner scanner = new Scanner(System.in);
        if (scanner.hasNextInt()){
            i = scanner.nextInt();
            if (i<=0){
                System.out.println("请输入一个大于0的数");
                System.exit(1);
            }
        } else {
            System.out.println("请输入一个大于0的数");
            System.exit(1);
        }

        for (int j = 0; j < i; j++) {
            formula Formula = new formula();
            String []str1 = Formula.Formulanobracket();
            String str = Formula.Bracket(str1);
            ShuntingYard shunt = new ShuntingYard();
            MyDC dc = new MyDC();
            String expr = shunt.getEquation(str);
            try {
                String result = dc.calculate(expr);//输出计算结果
                System.out.print(str + "= ");
                try {
                    String anwser = scanner.next();
                    if (anwser.equals(result)) {
                        System.out.println("正确！\n");
                        count++;
                    } else {
                        System.out.println("错误！正确答案为：" + result + "\n");
                    }
                } catch (InputMismatchException e2) {
                    scanner = new Scanner(System.in);
                    System.out.println("错误！正确答案为：" + result + "\n");
                }
            } catch (ArithmeticException e) {
                j--;
            }
        }
        System.out.println("完成" + i + "道题，正确率为" + (double) count / i * 100 + "%");
    }
}